package com.example.rpsm_property.service;

import com.example.rpsm_property.mapper.UserMapper;
import com.example.rpsm_property.pojo.PageResult;
import com.example.rpsm_property.pojo.User;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;
    @Override
    //新增 account 可能触发唯一索引的异常
    public int insertUser(User user) throws
            DuplicateKeyException, Exception {
        int result;
        result = userMapper.insertUser(user);
        return result;
    }

    @Override
    public PageResult<User> pageOfOwner(int current, int size) {
        PageHelper.startPage(current,size);
        Page<User> page = userMapper.owners();
        return PageResult.restPage(page);
    }

    /**
     * @param user
     * @return
     */
    @Override
    public int changeUserStatus(User user) {
        return userMapper.changeUserStatus(user);
    }
    @Override
    public User queryById(int id) {
        return userMapper.queryById(id);}
}
